/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author nawma77
 */
public class Rational
{
private int t; //täljare
private int n; //nämnare
public Rational(int t, int n)
{
this.t = t; // this.t anger attributet t
this.n = (n==0)? 1 : n;
simplify();
}
public Rational mul(Rational r)
{
return new Rational(t*r.t, n*r.n);
}
public Rational div(Rational r)
{
return new Rational(t*r.n, n*r.t);
}
public Rational add(Rational r)
{
return new Rational(t*r.n + r.t*n, n*r.n);
}
public Rational sub(Rational r)
{
return new Rational(t*r.n - r.t*n, n*r.n);
}
public String toString()
{
return " "+t+ "/"+n+"";
}
private void simplify()
{
int c = gcd(t,n);
t=t/c;
n=n/c;
}

private int gcd(int a, int b)
{
return (a%b==0)? b : gcd(b,a%b);
}
/*public static void main(String args[])
{
Rational r1 = new Rational(1,2);
Rational r2 = new Rational(2,5);
Rational s = r1.add(r2);
Rational d = r1.sub(r2);
Rational p = r1.mul(r2);
Rational q = r1.div(r2);
Rational z = s.add(d).sub(p).mul(q).div(s);
System.out.println(r1);
System.out.println(r2);
System.out.println(s);
System.out.println(d);
System.out.println(p);
System.out.println(q);
System.out.println(z);
}*/
}
